package models

type Event struct {
	Model
	Uid int `gorm:"column:uid" json:"uid" form:"uid"`
	Username string `gorm:"column:username" json:"username" form:"username"`
	Action string `gorm:"column:action" json:"action" form:"action"`
	ActionMsg string `gorm:"column:action_msg" json:"action_msg" form:"action_msg"`
	ProjectId int `gorm:"column:project_id" json:"project_id" form:"project_id"`
	CId int `gorm:"column:c_id" json:"c_id" form:"c_id"`
	BuildId int `gorm:"column:build_id" json:"build_id" form:"build_id"`
}

func CreateEvent(e Event) error {
	return db.Create(&e).Error
}



func GetAllCiEvents() []Event {
	events := make([]Event, 0)
	db.Where("action != ?", "CiDelete").Where("c_id > 0").Find(&events)
	return events
}

func GetAllEventTimeBetween(st, et int) []Event {
	events := make([]Event, 0)
	db.Where("created_at BETWEEN ? AND ?", st, et).Order("created_at desc").Find(&events)
	return events
}